<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增公出')"/>
    <style>

        .mainBox {
            width: 90%;
            margin-top: 20px;
            position: absolute;
            top: 0px;
            left: 0px;
            bottom: 50px;
            overflow: auto;
        }

        .bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
        }

        .button-container {
            position: absolute;
            right: 15px;
        }
        body{
            background-color: #fff;
        }
        .layui-form-label{
            width: 90px;
        }
        .layui-input-block {
            margin-left: 120px;
        }
    </style>
</head>
<body>
<form id="formId" class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">人员</label>
                <div class="layui-input-block">
                    <input type="hidden" id="userId" name="userId">
                    <input type="text" id="username" name="username" placeholder="点击选择人员"
                        class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">开始日期</label>
                <div class="layui-input-block">
                    <div class="input-group date">
                        <input type="text" name="startDateStr" class="layui-input"
                            id="startDateStr" >
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">开始日期半天</label>
                <div class="layui-input-block">
                    <select name="startDateFlag">
                        <option value="am">上半段</option>
                        <option value="pm">下半段</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束日期</label>
                <div class="layui-input-block">
                    <div class="input-group date">
                        <input type="text" name="endDateStr" class="layui-input"
                            id="endDateStr" >
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">结束日期半天</label>
                <div class="layui-input-block">
                    <select name="endDateFlag">
                        <option value="am">上半段</option>
                        <option value="pm" selected>下半段</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="type"      dict-code="kq_offical_business_type" >
                        <option value="">所有</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">公出天数</label>
                <div class="layui-input-block">
                    <input type="text" name="days" placeholder="请输入公出天数"
                        class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <input type="text" name="describing" placeholder="请输入描述"
                        class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">附件</label>
                <div class="layui-input-block">
                    <input type="hidden" id="fileId" name="fileId" />
                    <input id="zyupload" class="layui-input"></input>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit="" lay-filter="officialBusiness-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-sm" id="formreset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var _form;
    layui.use(['form', 'jquery', 'laydate', 'dtree', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;
        let dtree = layui.dtree;
        let dictionary = layui.dictionary;

        let prefix = pName + "/kq/officialBusiness/"
        $('#username').click(function () {
            userUtil.initUserSelectMultiple("userId", "username", "考勤");
        })
        $('#zyupload').click(function () {
            fileUtil.initFileUpload("fileId", "zyupload",true);
        })
        laydate.render({
            elem: '#startDateStr'
        });
        laydate.render({
            elem: '#endDateStr'
        });

        form.on('submit(officialBusiness-save)', function (data) {
            let loading = layer.load();
            for (var key in data.field) {
                var type = $(data.form).find("input[name='" + key + "']").attr("type");
                if (type == "checkbox") {
                    var value = "";
                    $(data.form).find("input[name='" + key + "']:checked").each(function () {
                        value += $(this).val() + ",";
                    })
                    if (value != "") {
                        value = value.substr(0, value.length - 1);
                        data.field[key] = value;
                    }

                }
            }
            $.ajax({
                url: prefix + 'save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 1) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("officialBusiness-table");
                        });
                    } else {
                            layer.alert(result.msg, {icon: 2});
                        }
                }
            })
            return false;
        });
        $('#formreset').click(function(){
            $('#formId').find('input').val("")

            $('#scheStage').empty();
            _form.render("select");
        })
    });
</script>
</html>